package view;

//import javax.swing.JButton;
//import javax.swing.JLabel;
//import javax.swing.JTextField;
//
////<<<<<<< .mine
//import javax.swing.JPanel;
/**
 *
 * @author bee.benedicta
 */
//public class PanelPeriksaSuratDokumen extends JPanel {
//
//=======

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import model.Dokument;
import model.OraConnection;
import model.PengendaliPenerimaSuratDokumen;
import model.Surat;

import java.util.ArrayList;
import javax.swing.*;
import model.*;


public class PanelPeriksaSuratDokumen extends JPanel {

    private JLabel judulLabel, labelTanggalterima;
    private JTextField textTanggal;
    private JButton tombolLihatDokumen, tombolLihatSurat;
    private ArrayList<Dokument> data;
    private ArrayList<Surat> dok;

    public PanelPeriksaSuratDokumen() {
        setLayout(null);

        judulLabel = new JLabel("Panel Pemeriksa Kelengkapan Surat Dokumen");
        judulLabel.setBounds(95, 5, 300, 40);
        add(judulLabel);

//        labelTanggalterima = new JLabel("Tanggal Terima");
//        labelTanggalterima.setBounds(20, 50, 150, 20);
//        add(labelTanggalterima);
//
//        textTanggal = new JTextField(20);
//        textTanggal.setBounds(150, 50, 200, 20);
//        add(textTanggal);

        tombolLihatDokumen = new JButton("Lihat Dokumen");
        tombolLihatDokumen.setBounds(50, 100, 150, 20);
        add(tombolLihatDokumen);
        tombolLihatDokumen.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                menuLihatDaftarDokumenAction();
            }
        });

        tombolLihatSurat = new JButton("Lihat Surat");
        tombolLihatSurat.setBounds(250, 100, 150, 20);
        add(tombolLihatSurat);
        tombolLihatSurat.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                menuLihatDaftarSuratAction();
            }
        });
    }

    public void menuLihatDaftarDokumenAction() {
//        ArrayList<Dokument> dok = new ArrayList<Dokument>(PengendaliPenerimaSuratDokumen.DAFTAR_DOKUMEN);
//        PengendaliPenerimaSuratDokumen.bacaDaftarDokumen();
//        PengendaliPenerimaSuratDokumen dok1 = new PengendaliPenerimaSuratDokumen();
        data = new ArrayList<Dokument>();
        Connection conn = OraConnection.open("jdbc:oracle:thin:@172.23.9.185:1521:orcl", "MHS115314063", "MHS115314063");
        Statement statement = null;
        try {
            statement = conn.createStatement();
        } catch (SQLException ex) {
            Logger.getLogger(PanelPeriksaSuratDokumen.class.getName()).log(Level.SEVERE, null, ex);
        }
        String sql = "select * from dokumen";
        try {
            statement.execute(sql);
        } catch (SQLException ex) {
            Logger.getLogger(PanelPeriksaSuratDokumen.class.getName()).log(Level.SEVERE, null, ex);
        }
        ResultSet set = null;
        try {
            set = statement.executeQuery(sql);
        } catch (SQLException ex) {
            Logger.getLogger(PanelPeriksaSuratDokumen.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            while (set.next()) {
                Dokument dok = new Dokument();
                dok.setNomorDokument(set.getInt(1));
                dok.setPerihal(set.getString(2));
                dok.setAsalDokumen(set.getString(3));
                dok.setPenerimaDokumen(set.getString(4));
                dok.setTanggalTerima(set.getString(5));
                dok.setTempatPenyimpanan(set.getString(6));
                dok.setPetugasPenerima(set.getString(7));
                dok.setKeterangan(set.getString(8));
                data.add(dok);
            }
        } catch (SQLException ex) {
            Logger.getLogger(PanelPeriksaSuratDokumen.class.getName()).log(Level.SEVERE, null, ex);
        }

        PanelDaftarDokument panelDaftar = new PanelDaftarDokument(data);
        JFrame test2 = new JFrame();
//        test2.setLayout(null);
//        dok.bacaTabelDokumen();
        test2.getContentPane().add(panelDaftar);
//        test2.gett
        test2.setTitle("Daftar Dokument");
        test2.setSize(430, 300);
        test2.setVisible(true);
        System.out.println("tabel dokumen sudah diperiksa");
    }

//    public void menuLihatDaftarDokumenAction() {
//        JDialog test2 = new JDialog();
//        ArrayList<Dokument> dok = PengendaliPenerimaSuratDokumen.DAFTAR_DOKUMEN;
//        PanelDaftarDokument panelDaftar = new PanelDaftarDokument(dok);
//        test2.getContentPane().add(panelDaftar);
//        test2.setTitle("Daftar Dokument");
//        test2.setSize(430, 300);
//        test2.setVisible(true);
//
//    }


    public void menuLihatDaftarSuratAction() {
//        JDialog test3 = new JDialog();
//        ArrayList<Surat> surat = new ArrayList<Surat>(PengendaliPenerimaSuratDokumen.DAFTAR_SURAT);
//        PanelDaftarSurat panelSurat = new PanelDaftarSurat(surat);
//        test3.getContentPane().add(panelSurat);
//        test3.setTitle("Daftar Surat");
//        test3.setSize(430, 300);
//        test3.setVisible(true);
        dok = new ArrayList<Surat>();
        Connection conn = OraConnection.open("jdbc:oracle:thin:@172.23.9.185:1521:orcl", "MHS115314063", "MHS115314063");
        Statement statement = null;
        try {
            statement = conn.createStatement();
        } catch (SQLException ex) {
            Logger.getLogger(PanelPeriksaSuratDokumen.class.getName()).log(Level.SEVERE, null, ex);
        }
        String sql = "select * from surat";
        try {
            statement.execute(sql);
        } catch (SQLException ex) {
            Logger.getLogger(PanelPeriksaSuratDokumen.class.getName()).log(Level.SEVERE, null, ex);
        }
        ResultSet set = null;
        try {
            set = statement.executeQuery(sql);
        } catch (SQLException ex) {
            Logger.getLogger(PanelPeriksaSuratDokumen.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            while (set.next()) {
                Surat s = new Surat();
                s.setNomorSurat(set.getInt(1));
                s.setPerihal(set.getString(2));
                s.setAsalSurat(set.getString(3));
                s.setPenerimaSurat(set.getString(4));
                s.setTanggalTerima(set.getString(5));
                s.setLetakSurat(set.getString(6));
                s.setPetugasPenerima(set.getString(7));
                s.setKeterangan(set.getString(8));
                dok.add(s);
            }
        } catch (SQLException ex) {
            Logger.getLogger(PanelPeriksaSuratDokumen.class.getName()).log(Level.SEVERE, null, ex);
        }
        PanelDaftarSurat panelDaftar = new PanelDaftarSurat(dok);
        JFrame test2 = new JFrame();
//        test2.setLayout(null);
//        dok.bacaTabelDokumen();
        test2.getContentPane().add(panelDaftar);
//        test2.gett
        test2.setTitle("Daftar Suratt");
        test2.setSize(430, 300);
        test2.setVisible(true);
        System.out.println("tabel surat sudah diperiksa");
    }

//    public void menuLihatDaftarSuratAction(){
//        JDialog test3 = new JDialog();
//        ArrayList<Surat> surat = new ArrayList<Surat>(PengendaliPenerimaSuratDokumen.DAFTAR_SURAT);
//        PanelDaftarSurat panelSurat = new PanelDaftarSurat(surat);
//        test3.getContentPane().add(panelSurat);
//        test3.setTitle("Daftar Surat");
//        test3.setSize(430, 300);
//        test3.setVisible(true);
//    }
//    public void lihatDokumenAction(){
//        JDialog test = new JDialog();
//        test.setLayout(null);
//        PanelDaftarDokument dok = new PanelDaftarDokument();
//        test.getContentPane().add(dok);
//        test.setSize(200, 300);
//        test.setVisible(true);
//
//    }
//
//    public void lihatSuratAction(){
//        JDialog test1 = new JDialog();
//        PanelDaftarSurat surat = new PanelDaftarSurat();
//        test1.getContentPane().add(surat);
//        test1.setSize(200, 300);
//        test1.setVisible(true);
//
//    }
//    public void lihatDokumenAction(){
//        JDialog test = new JDialog();
//        test.setLayout(null);
//        PanelDaftarDokument dok = new PanelDaftarDokument();
//        PengendaliPenerimaSuratDokumen.bacaTabelDokumen();
//        test.getContentPane().add(dok);
//        test.setSize(200, 300);
//        test.setVisible(true);
//
//    }
//
//    public void lihatSuratAction(){
//        JDialog test1 = new JDialog();
//        PanelDaftarSurat surat = new PanelDaftarSurat();
//        test1.getContentPane().add(surat);
//        test1.setSize(200, 300);
//        test1.setVisible(true);
//
//    }
}
